from xml.etree.ElementTree import *

def ComplexSourceGetModule(module_id, streamType, srcTrack, dstTrack, filename):
	
	S_Module = Element("Module_"+str(module_id))
	S_Module.attrib["ElementaryStream"] = streamType
	S_Module.attrib["SourceTrack.DWD"] = str(srcTrack)
	S_Module.attrib["ComplexSourceTrack.DWD"] = str(dstTrack)
	S_Module.attrib["Filename"] = filename
	ret = S_Module

	return ret
 

def ComplexSourceGetSource(sourceList=[]):

	
	Source = Element("Sources")
	Module = Element("Module_0")
	Module.attrib["ComplexSource.DWD"] = "1"
	Source.append(Module)

	ModuleData = Element("ModuleData")
	
	i = 0		

	for sl in sourceList:
		ModuleData.append(ComplexSourceGetModule(i, sl['type'], sl['srctrack'], sl['dsttrack'], sl['filename']))
		i = i + 1

	Module.append(ModuleData)
	ret = Source

	return ret



lst = []
lst.append({'type': "VIDEO", 'srctrack': 0, 'dsttrack' : 0, 'filename': "\\\\10.221.173.231\\hd_audio_insert\\inbox\\wc.mxf"})
lst.append({'type': "AUDIO", 'srctrack': 0, 'dsttrack' : 1, 'filename': "\\\\10.221.173.231\\hd_audio_insert\\inbox\\wc.wav"})
lst.append({'type': "AUDIO", 'srctrack': 0, 'dsttrack' : 2, 'filename': "\\\\10.221.173.231\\hd_audio_insert\\inbox\\wc.wav"})
lst.append({'type': "AUDIO", 'srctrack': 0, 'dsttrack' : 3, 'filename': "\\\\10.221.173.231\\hd_audio_insert\\inbox\\wc.wav"})
lst.append({'type': "AUDIO", 'srctrack': 0, 'dsttrack' : 4, 'filename': "\\\\10.221.173.231\\hd_audio_insert\\inbox\\wc.wav"})
lst.append({'type': "AUDIO", 'srctrack': 0, 'dsttrack' : 5, 'filename': "\\\\10.221.173.231\\hd_audio_insert\\inbox\\wc.wav"})
lst.append({'type': "AUDIO", 'srctrack': 0, 'dsttrack' : 6, 'filename': "\\\\10.221.173.231\\hd_audio_insert\\inbox\\wc.wav"})
lst.append({'type': "AUDIO", 'srctrack': 0, 'dsttrack' : 7, 'filename': "\\\\10.221.173.231\\hd_audio_insert\\inbox\\wc.wav"})
s = ComplexSourceGetSource(lst)


print tostring(s, encoding="utf-8")

